
fn u8code(byte:&u8)->&'static str {
    match byte{
        0=>"q",
        1=>"请", 
        2=>"其", 
        3=>"前", 
        4=>"却", 
        5=>"M",  
        6=>"钱", 
        7=>"区", 
        8=>"亲", 
        9=>"全", 
        10=>"`", 
        11=>"w", 
        12=>"为",
        13=>"五",
        14=>"玩",
        15=>"哇",
        16=>"N", 
        17=>"问",
        18=>"无",
        19=>"网",
        20=>"未",
        21=>"~", 
        22=>"e", 
        23=>"娥",
        24=>"呃",
        25=>"饿",
        26=>"恶",
        27=>"B",
        28=>"鹅",
        29=>"厄",
        30=>"莪",
        31=>"噩",
        32=>"!",
        33=>"r",
        34=>"让",
        35=>"如",
        36=>"燃",
        37=>"若",
        38=>"C",
        39=>"热",
        40=>"仍",
        41=>"入",
        42=>"肉",
        43=>"@",
        44=>"t",
        45=>"天",
        46=>"贴",
        47=>"谈",
        48=>"塔",
        49=>"X",
        50=>"填",
        51=>"铁",
        52=>"糖",
        53=>"替",
        54=>"#",
        55=>"y",
        56=>"也",
        57=>"与",
        58=>"用",
        59=>"以",
        60=>"Z",
        61=>"鱼",
        62=>"药",
        63=>"耶",
        64=>"盐",
        65=>"$",
        66=>"o",
        67=>"噢",
        68=>"偶",
        69=>"欧",
        70=>"藕",
        71=>"L",
        72=>"耦",
        73=>"沤",
        74=>"讴",
        75=>"怄",
        76=>"%",
        77=>"p",
        78=>"篇",
        79=>"拍",
        80=>"跑",
        81=>"派",
        82=>"K",
        83=>"盘",
        84=>"破",
        85=>"排",
        86=>"屏",
        87=>"^",
        88=>"a",
        89=>"阿",
        90=>"吖",
        91=>"哎",
        92=>"安",
        93=>"J",
        94=>"凹",
        95=>"敖",
        96=>"氨",
        97=>"暗",
        98=>"&",
        99=>"s",
        100=>"6",
        101=>"啥",
        102=>"送",
        103=>"市",
        104=>"H",
        105=>"双",
        106=>"受",
        107=>"沙",
        108=>"1",
        109=>"*",
        110=>"d",
        111=>"7",
        112=>"对",
        113=>"等",
        114=>"到",
        115=>"G",
        116=>"点",
        117=>"大",
        118=>"得",
        119=>"2",
        120=>"-",
        121=>"f",
        122=>"8",
        123=>"放",
        124=>"风",
        125=>"飞",
        126=>"F",
        127=>"凡",
        128=>"服",
        129=>"复",
        130=>"3",
        131=>"_",
        132=>"g",
        133=>"9",
        134=>"跟",
        135=>"过",
        136=>"该",
        137=>"D",
        138=>"刚",
        139=>"光",
        140=>"够",
        141=>"4",
        142=>"=",
        143=>"h",
        144=>"0",
        145=>"还",
        146=>"会",
        147=>"后",
        148=>"S",
        149=>"很",
        150=>"哈",
        151=>"花",
        152=>"5",
        153=>"+",
        154=>"j",
        155=>"将",
        156=>"及",
        157=>"加",
        158=>"九",
        159=>"A",
        160=>"即",
        161=>"金",
        162=>"进",
        163=>"见",
        164=>"|",
        165=>"k",
        166=>"快",
        167=>"靠",
        168=>"科",
        169=>"空",
        170=>"P",
        171=>"库",
        172=>"款",
        173=>"壳",
        174=>"凯",
        175=>";",
        176=>"l",
        177=>"来",
        178=>"零",
        179=>"里",
        180=>"啦",
        181=>"O",
        182=>"六",
        183=>"连",
        184=>"拉",
        185=>"类",
        186=>":",
        187=>"z",
        188=>"这",
        189=>"再",
        190=>"之",
        191=>"找",
        192=>"Y",
        193=>"最",
        194=>"着",
        195=>"者",
        196=>"子",
        197=>",",
        198=>"x",
        199=>"先",
        200=>"小",
        201=>"向",
        202=>"行",
        203=>"T",
        204=>"写",
        205=>"雪",
        206=>"笑",
        207=>"信",
        208=>"<",
        209=>"c",
        210=>"才",
        211=>"出",
        212=>"成",
        213=>"车",
        214=>"R",
        215=>"称",
        216=>"超",
        217=>"穿",
        218=>"错",
        219=>".",
        220=>"b",
        221=>"不",
        222=>"把",
        223=>"被",
        224=>"并",
        225=>"E",
        226=>"冰",
        227=>"帮",
        228=>"版",
        229=>"包",
        230=>">",
        231=>"n",
        232=>"呢",
        233=>"那",
        234=>"泥",
        235=>"年",
        236=>"W",
        237=>"拿",
        238=>"念",
        239=>"弄",
        240=>"哪",
        241=>"?",
        242=>"m",
        243=>"没",
        244=>"么",
        245=>"嘛",
        246=>"买",
        247=>"Q",
        248=>"卖",
        249=>"名",
        250=>"美",
        251=>"米",
        252=>"/",
        253=>"u",
        254=>"i",
        255=>"v",
    }
}
fn decou8(zi:&str)->Option<u8>{
    match zi{
        "q"=>Some(0),
        "请"=>Some(1), 
        "其"=>Some(2), 
        "前"=>Some(3), 
        "却"=>Some(4), 
        "M"=>Some(5),  
        "钱"=>Some(6), 
        "区"=>Some(7), 
        "亲"=>Some(8), 
        "全"=>Some(9), 
        "`"=>Some(10), 
        "w"=>Some(11), 
        "为"=>Some(12),
        "五"=>Some(13),
        "玩"=>Some(14),
        "哇"=>Some(15),
        "N"=>Some(16), 
        "问"=>Some(17),
        "无"=>Some(18),
        "网"=>Some(19),
        "未"=>Some(20),
        "~"=>Some(21),
        "e"=>Some(22),
        "娥"=>Some(23),
        "呃"=>Some(24),
        "饿"=>Some(25),
        "恶"=>Some(26),
        "B"=>Some(27),
        "鹅"=>Some(28),
        "厄"=>Some(29),
        "莪"=>Some(30),
        "噩"=>Some(31),
        "!"=>Some(32),
        "r"=>Some(33),
        "让"=>Some(34),
        "如"=>Some(35),
        "燃"=>Some(36),
        "若"=>Some(37),
        "C"=>Some(38),
        "热"=>Some(39),
        "仍"=>Some(40),
        "入"=>Some(41),
        "肉"=>Some(42),
        "@"=>Some(43),
        "t"=>Some(44),
        "天"=>Some(45),
        "贴"=>Some(46),
        "谈"=>Some(47),
        "塔"=>Some(48),
        "X"=>Some(49),
        "填"=>Some(50),
        "铁"=>Some(51),
        "糖"=>Some(52),
        "替"=>Some(53),
        "#"=>Some(54),
        "y"=>Some(55),
        "也"=>Some(56),
        "与"=>Some(57),
        "用"=>Some(58),
        "以"=>Some(59),
        "Z"=>Some(60),
        "鱼"=>Some(61),
        "药"=>Some(62),
        "耶"=>Some(63),
        "盐"=>Some(64),
        "$"=>Some(65),
        "o"=>Some(66),
        "噢"=>Some(67),
        "偶"=>Some(68),
        "欧"=>Some(69),
        "藕"=>Some(70),
        "L"=>Some(71),
        "耦"=>Some(72),
        "沤"=>Some(73),
        "讴"=>Some(74),
        "怄"=>Some(75),
        "%"=>Some(76),
        "p"=>Some(77),
        "篇"=>Some(78),
        "拍"=>Some(79),
        "跑"=>Some(80),
        "派"=>Some(81),
        "K"=>Some(82),
        "盘"=>Some(83),
        "破"=>Some(84),
        "排"=>Some(85),
        "屏"=>Some(86),
        "^"=>Some(87),
        "a"=>Some(88),
        "阿"=>Some(89),
        "吖"=>Some(90),
        "哎"=>Some(91),
        "安"=>Some(92),
        "J"=>Some(93),
        "凹"=>Some(94),
        "敖"=>Some(95),
        "氨"=>Some(96),
        "暗"=>Some(97),
        "&"=>Some(98),
        "s"=>Some(99),
        "6"=>Some(100),
        "啥"=>Some(101),
        "送"=>Some(102),
        "市"=>Some(103),
        "H"=>Some(104),
        "双"=>Some(105),
        "受"=>Some(106),
        "沙"=>Some(107),
        "1"=>Some(108),
        "*"=>Some(109),
        "d"=>Some(110),
        "7"=>Some(111),
        "对"=>Some(112),
        "等"=>Some(113),
        "到"=>Some(114),
        "G"=>Some(115),
        "点"=>Some(116),
        "大"=>Some(117),
        "得"=>Some(118),
        "2"=>Some(119),
        "-"=>Some(120),
        "f"=>Some(121),
        "8"=>Some(122),
        "放"=>Some(123),
        "风"=>Some(124),
        "飞"=>Some(125),
        "F"=>Some(126),
        "凡"=>Some(127),
        "服"=>Some(128),
        "复"=>Some(129),
        "3"=>Some(130),
        "_"=>Some(131),
        "g"=>Some(132),
        "9"=>Some(133),
        "跟"=>Some(134),
        "过"=>Some(135),
        "该"=>Some(136),
        "D"=>Some(137),
        "刚"=>Some(138),
        "光"=>Some(139),
        "够"=>Some(140),
        "4"=>Some(141),
        "="=>Some(142),
        "h"=>Some(143),
        "0"=>Some(144),
        "还"=>Some(145),
        "会"=>Some(146),
        "后"=>Some(147),
        "S"=>Some(148),
        "很"=>Some(149),
        "哈"=>Some(150),
        "花"=>Some(151),
        "5"=>Some(152),
        "+"=>Some(153),
        "j"=>Some(154),
        "将"=>Some(155),
        "及"=>Some(156),
        "加"=>Some(157),
        "九"=>Some(158),
        "A"=>Some(159),
        "即"=>Some(160),
        "金"=>Some(161),
        "进"=>Some(162),
        "见"=>Some(163),
        "|"=>Some(164),
        "k"=>Some(165),
        "快"=>Some(166),
        "靠"=>Some(167),
        "科"=>Some(168),
        "空"=>Some(169),
        "P"=>Some(170),
        "库"=>Some(171),
        "款"=>Some(172),
        "壳"=>Some(173),
        "凯"=>Some(174),
        ";"=>Some(175),
        "l"=>Some(176),
        "来"=>Some(177),
        "零"=>Some(178),
        "里"=>Some(179),
        "啦"=>Some(180),
        "O"=>Some(181),
        "六"=>Some(182),
        "连"=>Some(183),
        "拉"=>Some(184),
        "类"=>Some(185),
        ":"=>Some(186),
        "z"=>Some(187),
        "这"=>Some(188),
        "再"=>Some(189),
        "之"=>Some(190),
        "找"=>Some(191),
        "Y"=>Some(192),
        "最"=>Some(193),
        "着"=>Some(194),
        "者"=>Some(195),
        "子"=>Some(196),
        ","=>Some(197),
        "x"=>Some(198),
        "先"=>Some(199),
        "小"=>Some(200),
        "向"=>Some(201),
        "行"=>Some(202),
        "T"=>Some(203),
        "写"=>Some(204),
        "雪"=>Some(205),
        "笑"=>Some(206),
        "信"=>Some(207),
        "<"=>Some(208),
        "c"=>Some(209),
        "才"=>Some(210),
        "出"=>Some(211),
        "成"=>Some(212),
        "车"=>Some(213),
        "R"=>Some(214),
        "称"=>Some(215),
        "超"=>Some(216),
        "穿"=>Some(217),
        "错"=>Some(218),
        "."=>Some(219),
        "b"=>Some(220),
        "不"=>Some(221),
        "把"=>Some(222),
        "被"=>Some(223),
        "并"=>Some(224),
        "E"=>Some(225),
        "冰"=>Some(226),
        "帮"=>Some(227),
        "版"=>Some(228),
        "包"=>Some(229),
        ">"=>Some(230),
        "n"=>Some(231),
        "呢"=>Some(232),
        "那"=>Some(233),
        "泥"=>Some(234),
        "年"=>Some(235),
        "W"=>Some(236),
        "拿"=>Some(237),
        "念"=>Some(238),
        "弄"=>Some(239),
        "哪"=>Some(240),
        "?"=>Some(241),
        "m"=>Some(242),
        "没"=>Some(243),
        "么"=>Some(244),
        "嘛"=>Some(245),
        "买"=>Some(246),
        "Q"=>Some(247),
        "卖"=>Some(248),
        "名"=>Some(249),
        "美"=>Some(250),
        "米"=>Some(251),
        "/"=>Some(252),
        "u"=>Some(253),
        "i"=>Some(254),
        "v"=>Some(255),
        _=>None
    }
}

pub fn codestr(strbuf:&[u8])->String{
    let mut rs = String::new();
    let mut mix:usize = 0;
    for idx in strbuf{
        let tmp = idx^mix as u8;
        rs.push_str(u8code(&tmp));
        mix+=1
    }
    rs
}
pub fn codestr_word(strbuf:&[u8],words:&[u8])->String{
    let mut rs = String::new();
    let mut mix:usize = 0;
    let wlen = words.len();
    for idx in strbuf{
        let tmp = idx^mix as u8^words[mix%wlen];
        rs.push_str(u8code(&tmp));
        mix+=1
    }
    rs
}
pub fn decodestr(strbuf:&str)->Result<String, ()>{
    let mut uu8 = Vec::new();
    let mut mix:usize = 0;
    for idx in strbuf.chars(){
        if let Some(codeu) = decou8(&idx.to_string()){
            uu8.push(codeu^mix as u8);
            mix+=1;
        }
    }
    match std::str::from_utf8(&uu8){
        Ok(s) => Ok(s.to_string()),
        Err(_) => Err(()),
    }
}
pub fn decodeu8(strbuf:&str)->Vec<u8>{
    let mut uu8 = Vec::new();
    let mut mix:u64 = 0;
    for idx in strbuf.chars(){
        if let Some(codeu) = decou8(&idx.to_string()){
            uu8.push(codeu^mix as u8);
            mix+=1;
        }
    }
    uu8
}
pub fn decodestr_word(strbuf:&str,words:&[u8])->Result<String,()>{
    let mut uu8 = Vec::new();
    let mut mix:usize = 0;
    let wlen = words.len();
    for idx in strbuf.chars(){
        if let Some(codeu) = decou8(&idx.to_string()){
            uu8.push(codeu^mix as u8^words[mix%wlen]);
            mix+=1;
        }
    }
    match std::str::from_utf8(&uu8){
        Ok(s) => Ok(s.to_string()),
        Err(_) => Err(()),
    }
}
pub fn decodeu8_word(strbuf:&str,words:&[u8])->Vec<u8>{
    let mut uu8 = Vec::new();
    let mut mix:usize = 0;
    let wlen = words.len();
    for idx in strbuf.chars(){
        if let Some(codeu) = decou8(&idx.to_string()){
            uu8.push(codeu^mix as u8^words[mix%wlen]);
            mix+=1;
        }
    }
    uu8
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn isiswork(){
        let mut dd = "yyds";
        let ddsd = codestr_word(dd.as_bytes(),"2222".as_bytes());
        println!("{}",ddsd);
        if let Ok(sdsd) = decodestr_word(&ddsd,"1414".as_bytes()){
            println!("-{}-",sdsd);
        }
    }
}
